"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
//属性装饰器
//基本语法
// 参数说明：
//  ○ target: 对于静态属性来说值是类，对于实例属性来说值是类的原型对象。
//  ○ propertyKey: 属性名。
function CustomxDemo(target, propertyKey) {
    console.log(target, propertyKey);
}
// 如下代码中：当构造器中的 this.age = age 试图在实例上赋值时，实际上是调⽤了原型上age 属性的 set ⽅法。
class Person20 {
    constructor(name, age) {
        this.age = age;
        this.name = name;
    }
}
__decorate([
    CustomxDemo
], Person20.prototype, "name", void 0);
__decorate([
    CustomxDemo
], Person20.prototype, "age", void 0);
__decorate([
    CustomxDemo
], Person20, "school", void 0);
// let value20 = 130
// Object.defineProperty(Person20.prototype, 'age', {
//     get() {
//         return value20
//     },
//     set(val) {
//         value20 = val
//     }
// })
const p20 = new Person20('张三', 18);
console.log(p20);
//应⽤举例
//需求：定义⼀个 State 属性装饰器，来监视属性的修改。
function Statexx(target, propertyKey) {
    let key = `__${propertyKey}`;
    Object.defineProperty(target, propertyKey, {
        get() {
            return this[key];
        },
        set(val) {
            console.log(`${propertyKey}的最新值为：${val}`);
            return this[key] = val;
        },
        //可枚举型
        enumerable: true,
        configurable: true,
    });
}
class Person21 {
    constructor(name, age) {
        this.name = name;
        this.age = age;
    }
}
__decorate([
    Statexx
], Person21.prototype, "age", void 0);
const p21 = new Person21('张三', 18);
console.log(p21);
